﻿using ModelClassLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace SplitViewOptions
{
    public class SitesInfo
    {
        public string name { get; set; }
        public string type { get; set; }
        public string Domain { get; set; }
        public string Contant { get; set; }
    }
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class Top100page : Page
    {
        public Top100page()
        {
            this.InitializeComponent();
        }
        protected  override void OnNavigatedTo(NavigationEventArgs e)
        {
        
            if (e.NavigationMode == NavigationMode.New)
            {
                Gettop100();
                //  List<Info> allsite = await BmobWebsiteData.Getrecommendsites(App.recommendsiteurl);
                // navigateviewer.ItemsSource = Gettop100();
            }
            base.OnNavigatedTo(e);
        }
        private List<SitesInfo> Gettop100()
        {
            try
            {
                List<SitesInfo> listnew = new List<SitesInfo>();
                listnew.Add(new SitesInfo { Domain = "http://www.360.cn", name = "360 Safeguard", Contant = "3", type = "Software and technology" });
                listnew.Add(new SitesInfo { Domain = "http://www.amazon.com", name = "Amazon", Contant = "A", type = "E-commerce and cloud computing" });
                listnew.Add(new SitesInfo { Domain = "http://www.baidu.com", name = "Baidu", Contant = "B", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.CNN.com", name = "CNN", Contant = "C", type = "News" });
                listnew.Add(new SitesInfo { Domain = "http://www.Dibold.com", name = "Diebold", Contant = "D", type = "Industry" });
                listnew.Add(new SitesInfo { Domain = "http://www.ebay.com", name = "eBay", Contant = "E", type = "Online auctions and shopping" });
                listnew.Add(new SitesInfo { Domain = "http://www.facebook.com", name = "Facebook", Contant = "F", type = "Social network" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.co.in", name = "Google India", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.co.jp", name = "Google Japan", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.com", name = "Google", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.hao123.com", name = "Hao123", Contant = "H", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.instagram.com", name = "Instagram", Contant = "I", type = "Photo sharing and social media" });
                listnew.Add(new SitesInfo { Domain = "http://www.jd.com", name = "Jingdong Mall", Contant = "J", type = "E-commerce" });
                listnew.Add(new SitesInfo { Domain = "http://www.kat.cr", name = "KickassTorrents", Contant = "K", type = "Directory for torrents" });
                listnew.Add(new SitesInfo { Domain = "http://www.linkedin.com", name = "LinkedIn", Contant = "L", type = "Social network" });
                listnew.Add(new SitesInfo { Domain = "http://www.msn.com", name = "MSN", Contant = "M", type = "Portal" });
                listnew.Add(new SitesInfo { Domain = "http://www.netflix.com", name = "Netflix", Contant = "N", type = "Streaming TV and movies" });
                listnew.Add(new SitesInfo { Domain = "http://www.ok.ru", name = "Odnoklassniki", Contant = "O", type = "Social Networking" });
                listnew.Add(new SitesInfo { Domain = "http://www.pornhub.com", name = "Pornhub", Contant = "P", type = "Pornography" });
                listnew.Add(new SitesInfo { Domain = "http://www.qq.com", name = "Tencent QQ", Contant = "Q", type = "Portal" });
                listnew.Add(new SitesInfo { Domain = "http://www.rakuten.co.jp", name = "Rakuten", Contant = "R", type = "E-commerce" });
                listnew.Add(new SitesInfo { Domain = "http://www.weibo.com", name = "Sina Weibo", Contant = "S", type = "Social network" });
                listnew.Add(new SitesInfo { Domain = "http://www.sina.com.cn", name = "Sina Corp", Contant = "S", type = "Portal" });
                listnew.Add(new SitesInfo { Domain = "http://www.taobao.com", name = "Taobao", Contant = "T", type = "Online shopping" });
                listnew.Add(new SitesInfo { Domain = "http://www.twitter.com", name = "Twitter", Contant = "T", type = "Social network" });
                listnew.Add(new SitesInfo { Domain = "http://www.vk.com", name = "VK", type = "Social network", Contant = "V" });
                listnew.Add(new SitesInfo { Domain = "http://www.live.com", name = "Windows Live", Contant = "W", type = "Email, web services and software suite" });
                listnew.Add(new SitesInfo { Domain = "http://www.wikipedia.org", name = "Wikipedia", Contant = "W", type = "Encyclopedia" });
                listnew.Add(new SitesInfo { Domain = "http://www.xhamster.com", name = "xHamster", Contant = "X", type = "Pornography" });
                listnew.Add(new SitesInfo { Domain = "http://www.yahoo.com", name = "Yahoo!", Contant = "Y", type = "Portal" });
                listnew.Add(new SitesInfo { Domain = "http://www.yandex.ru", name = "Yandex", Contant = "Y", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.yahoo.co.jp", name = "Yahoo! Japan", Contant = "Y", type = "Portal" });
                listnew.Add(new SitesInfo { Domain = "http://www.bing.com", name = "Bing", Contant = "B", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.de", name = "Google Germany", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.t.co", name = "t.co", Contant = "T", type = "URL shortening for links posted to Twitter" });
                listnew.Add(new SitesInfo { Domain = "http://www.aliexpress.com", name = "AliExpress", Contant = "A", type = "Online shopping" });
                listnew.Add(new SitesInfo { Domain = "http://www.amazon.co.jp", name = "Amazon Japan", Contant = "A", type = "E-commerce" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.co.uk", name = "Google UK", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.apple.com", name = "Apple Inc.", Contant = "A", type = "Technology and software" });
                listnew.Add(new SitesInfo { Domain = "http://www.blogspot.com", name = "Blogspot", Contant = "B", type = "Blogging" });
                listnew.Add(new SitesInfo { Domain = "http://www.ask.com", name = "Ask.com", Contant = "A", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.pinterest.com", name = "Pinterest", Contant = "P", type = "Social media" });
                listnew.Add(new SitesInfo { Domain = "http://www.wordpress.com", name = "WordPress.com", Contant = "W", type = "Blogging and social media" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.fr", name = "Google France", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.tmall.com", name = "Tmall", Contant = "T", type = "Retail" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.com.br", name = "Google Brazil", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.reddit.com", name = "Reddit", Contant = "R", type = "Entertainment and social news networking" });
                listnew.Add(new SitesInfo { Domain = "http://www.mail.ru", name = "Mail.Ru", Contant = "M", type = "Email" });
                listnew.Add(new SitesInfo { Domain = "http://www.onclickads.net", name = "Onclickads", Contant = "O", type = "Online advertising network" });
                listnew.Add(new SitesInfo { Domain = "http://www.paypal.com", name = "PayPal", Contant = "P", type = "Payment system" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.ru", name = "Google Russia", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.sohu.com", name = "Sohu", Contant = "S", type = "Portal" });
                listnew.Add(new SitesInfo { Domain = "http://www.tumblr.com", name = "Tumblr", Contant = "T", type = "Social media" });
                listnew.Add(new SitesInfo { Domain = "http://www.imgur.com", name = "Imgur", Contant = "I", type = "Image sharing" });
                listnew.Add(new SitesInfo { Domain = "http://www.microsoft.com", name = "Microsoft", Contant = "M", type = "Software and technology" });
                listnew.Add(new SitesInfo { Domain = "http://www.xvideos.com", name = "XVideos", Contant = "X", type = "Pornography" });
                listnew.Add(new SitesInfo { Domain = "http://www.gmw.cn", name = "Guangming Daily", Contant = "G", type = "News" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.it", name = "Google Italy", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.es", name = "Google Spain", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.imdb.com", name = "Internet Movie Database", Contant = "I", type = "Database of films, television programs, and video games" });
                listnew.Add(new SitesInfo { Domain = "http://www.fc2.com", name = "FC2, Inc.", Contant = "F", type = "Portal" });
                listnew.Add(new SitesInfo { Domain = "http://www.amazon.de", name = "Amazon Germany", Contant = "A", type = "E-commerce" });
                listnew.Add(new SitesInfo { Domain = "http://www.googleadservices.com", name = "Google Ads", Contant = "G", type = "Online advertising network" });
                listnew.Add(new SitesInfo { Domain = "http://www.go.com", name = "Go.com", Contant = "G", type = "Portal" });
                listnew.Add(new SitesInfo { Domain = "http://www.stackoverflow.com", name = "Stack Overflow", Contant = "S", type = "Question and answer site" });
                listnew.Add(new SitesInfo { Domain = "http://www.alibaba.com", name = "Alibaba Group", Contant = "A", type = "E-commerce and portal" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.com.mx", name = "Google Mexico", Contant = "G", type = "Search Engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.ca", name = "Google Canada", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.craigslist.org", name = "Craigslist", Contant = "C", type = "Classified advertising" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.com.hk", name = "Google Hong Kong", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.tianya.cn", name = "Tianya Club", Contant = "T", type = "Internet forum" });
                listnew.Add(new SitesInfo { Domain = "http://www.amazon.co.uk", name = "Amazon UK", Contant = "A", type = "E-commerce" });
                listnew.Add(new SitesInfo { Domain = "http://www.blogger.com", name = "Blogger", Contant = "B", type = "Blogging" });
                listnew.Add(new SitesInfo { Domain = "http://www.Naver.com", name = "Naver", Contant = "N", type = "Portal" });
                listnew.Add(new SitesInfo { Domain = "http://www.espn.go.com", name = "ESPN", Contant = "E", type = "Sports news" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.com.tr", name = "Google Turkey", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.cnn.com", name = "CNN", Contant = "C", type = "News" });
                listnew.Add(new SitesInfo { Domain = "http://www.outbrain.com", name = "Outbrain", Contant = "O", type = "Content marketing" });
                listnew.Add(new SitesInfo { Domain = "http://www.soso.com", name = "Soso.com", Contant = "S", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.nicovideo.jp", name = "Nicovideo", Contant = "N", type = "Video sharing" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.co.id", name = "Google Indonesia", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.xinhuanet.com", name = "Xinhua News Agency", Contant = "X", type = "News" });
                listnew.Add(new SitesInfo { Domain = "http://www.bbc.co.uk", name = "BBC Online", Contant = "B", type = "News and broadcasting" });
                listnew.Add(new SitesInfo { Domain = "http://www.flipkart.com", name = "Flipkart", Contant = "F", type = "Retail" });
                listnew.Add(new SitesInfo { Domain = "http://www.diply.com", name = "Diply", Contant = "D", type = "Entertainment" });
                listnew.Add(new SitesInfo { Domain = "http://www.dropbox.com", name = "Dropbox", Contant = "D", type = "File hosting service" });
                listnew.Add(new SitesInfo { Domain = "http://www.github.com", name = "GitHub", Contant = "G", type = "Source code hosting service" });
                listnew.Add(new SitesInfo { Domain = "http://www.googleusercontent.com", Contant = "G", name = "Google User Content", type = "File hosting service" });
                listnew.Add(new SitesInfo { Domain = "http://www.adcash.com", name = "Adcash", Contant = "A", type = "Online advertising network" });
                listnew.Add(new SitesInfo { Domain = "http://www.amazon.in", name = "Amazon India", Contant = "A", type = "E-commerce" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.com.au", name = "Google Australia", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.ebay.de", name = "eBay Germany", Contant = "E", type = "Online auctions and shopping" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.co.kr", name = "Google Korea", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.google.pl", name = "Google Poland", Contant = "G", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.popads.net", name = "Popads", Contant = "P", type = "Online advertising network" });
                listnew.Add(new SitesInfo { Domain = "http://www.dailymotion.com", name = "Dailymotion", Contant = "D", type = "Video sharing" });
                listnew.Add(new SitesInfo { Domain = "http://www.pixnet.net", name = "Pixnet", Contant = "P", type = "Blogging" });
                listnew.Add(new SitesInfo { Domain = "http://www.nytimes.com", name = "New York Times", Contant = "N", type = "News" });
                listnew.Add(new SitesInfo { Domain = "http://www.ebay.co.uk", name = "eBay UK", Contant = "E", type = "Online auctions and shopping" });
                listnew.Add(new SitesInfo { Domain = "http://www.sogou.com", name = "Sogou", Contant = "S", type = "Search engine" });
                listnew.Add(new SitesInfo { Domain = "http://www.booking.com", name = "Booking.com", Contant = "B", type = "Accommodation booking" });

                foreach (var a in listnew)
                {
                    Debug.WriteLine("filestr.Add(\"" + a.Domain.Replace("www", "*") + "\");");
                  
                }
                foreach (var a in listnew)
                {
                    
                    Debug.WriteLine("<uap:Rule Match =\"" + a.Domain.Replace("www", "*") + "\" Type = \"include\"  WindowsRuntimeAccess = \"all\" />");
                }
                List<ItemInGroup> Items = (from Item in listnew group Item by Item.Contant into newItems select new ItemInGroup { Key = newItems.Key, ItemContant = newItems.ToList() }).ToList();
                this.itemcollectionSource.Source = Items;
                outView.ItemsSource = itemcollectionSource.View.CollectionGroups;
                inView.ItemsSource = itemcollectionSource.View;
                return listnew;
            }
            catch(Exception ex)
            {
                List<SitesInfo> listnew = new List<SitesInfo>();
                return listnew;
            }
            
        }

        private void Border_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Border obj = sender as Border;
            SitesInfo oneinfo = obj.DataContext as SitesInfo;

            App.Currenturl = new Uri(oneinfo.Domain, UriKind.RelativeOrAbsolute);
            this.Frame.Navigate(typeof(HomePage));
         //   App.iswithoutpicmode = false;
         //   App.isdownloadstirngmode = false;

        }

        private void Grid_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Grid obj = sender as Grid;
            SitesInfo oneinfo = obj.DataContext as SitesInfo;

            App.Currenturl = new Uri(oneinfo.Domain, UriKind.RelativeOrAbsolute);
            this.Frame.Navigate(typeof(HomePage));
        }
    }
    public class ItemInGroup
    {
        public string Key { get; set; }
        public List<SitesInfo> ItemContant { get; set; }
    }
}
